//
//  SuperviseArrageRecordView.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/1/6.
//

import Foundation
import UIKit

class SuperviseArrageRecordView: UIScrollView {
    let basicV = UIView.createBase()
    let nameL = UILabel()    
    let resultItem = InspListDetailItem()    // 检查结论
    let personItem = InspListDetailItem()  // 整改人

    let recordV = UIView.createBase()

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .bg
        showsVerticalScrollIndicator = false
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func reload(withModal modal: Any) {
        nameL.text = "18门、窗、防盗栅、锁具未保持完好，二层(5米)以下 窗户内侧未安装金属防护栏或未采取相应防护措施，窗 应安装限位装置。"
        resultItem.update(withKey: "检查结论:", value: "不合格")
        personItem.update(withKey: "整改人:", value: "张启明")
    }
    
    func setupBasicUI() {
        addSubview(basicV)
        basicV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        nameL.numberOfLines = 0
        nameL.font = .systemFont(ofSize: 15)
        basicV.addSubview(nameL)
        nameL.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(20)
            make.top.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
        }
        
        let line = UIView()
        line.backgroundColor = .hex("#EFEFEF")
        basicV.addSubview(line)
        line.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(nameL.snp.bottom).offset(26)
            make.left.equalTo(nameL.snp.left)
            make.right.equalTo(nameL.snp.right)
            make.height.equalTo(0.5)
        }

        basicV.addSubview(resultItem)
        resultItem.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(line.snp.bottom).offset(10)
            make.height.equalTo(40)
        }
        
        basicV.addSubview(personItem)
        personItem.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(resultItem.snp.bottom)
            make.height.equalTo(40)
            make.bottom.equalToSuperview().offset(-12)
        }
    }
    
    func setupRecordUI() {
        addSubview(recordV)
        recordV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.top.equalTo(basicV.snp.bottom).offset(10)
            make.right.equalToSuperview().offset(-10)
            make.width.equalTo(ScreenWidth - 20)
        }
    }
    
    func setupUI() {
        // 基本信息
        setupBasicUI()
        
        // 整改记录
        setupRecordUI()
    }
}
